#include "../tools.h"

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int len = nums.size();
        if(len == 0) return 0;

        
        int res = len;
        bool flag = false;
        int start = 0, end = 0, sum = 0;
        while(end < len){ // 满足条件，滑动 end
            sum += nums[end];
            while(sum >= target){ // 满足条件，滑动 start
                flag = true;
                cout << start << "-" << end << endl;
                int dis = end - start + 1;
                if(dis < res) res = dis;
                sum -= nums[start];
                ++start;
            }
            ++end;
        }

        if(flag) return res;
        return 0;
    }
};

int main(int argc, char const *argv[])
{
    
    int target = 11;
    vector<int> nums = {1,1,1,1,1,1,1,1};

    Solution s;
    int res = s.minSubArrayLen(target, nums);
    cout << res << endl;
    
    return 0;
}
